//
//  TicketView.swift
//  AirlineReservation
//
//  Created by Kevin on 2020/1/18.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class TicketView: UIButton {
    
    // 文本
    private lazy var textView = UILabel()
    // 图片
    private lazy var iconView = UIImageView()
    
    var text:String? {
        didSet {
            textView.text = text
        }
    }

    var image:UIImage? {
        didSet {
            iconView.image = image
        }
    }
    
    override func layoutSubviews() {
        // 图片
        let iconX = frame.width * 0.5 - (image?.size.width)! * 0.5
        let iconW = frame.size.width
        iconView.frame = CGRect(x: iconX, y: MARGIN10, width: 56, height: 67)
        // 文本
        let textW = frame.width
        let textH = MARGIN15
        let textX = iconW * 0.5 - textW * 0.5
        textView.textAlignment = .center
        textView.textColor = COLOR_NICE
        textView.font = UIFont.systemFont(ofSize: 12)
        textView.frame = CGRect(x: textX, y: iconView.frame.maxY, width: textW, height: textH)
        // 添加到父控件上
        addSubview(iconView)
        addSubview(textView)
    }
}
